// 导入axios模块
import request from '@/utils/request'

// 文章分类相关 api
// 渲染文章分类数据
export const InitClass = () => {
  return request.get('/my/cate/list', {})
}

// 获取文章分类详情
export const getClass = (id) => {
  return request.get('/my/cate/info', {
    params: {
      id
    }
  })
}

// 增加文章分类
export const addClass = (cate_name, cate_alias) => {
  return request.post('/my/cate/add', {
    cate_name,
    cate_alias
  })
}
// 删除文章分类
export const delClass = (id) => {
  return request.delete('/my/cate/del', {
    params: {
      id
    }
  })
}
// 修改文章分类
export const changeClass = (cate_name, cate_alias, id) => {
  return request.put('/my/cate/info', {
    cate_name,
    cate_alias,
    id
  })
}

// 文章相关api

// 渲染文章分类数据
export const initArticleList = (pagenum, pagesize, cate_id, state) => {
  if (cate_id && !state) {
    return request.get('/my/article/list', {
      params: {
        pagenum, pagesize, cate_id
      }
    })
  } else if (!cate_id && state) {
    return request.get('/my/article/list', {
      params: {
        pagenum, pagesize, state
      }
    })
  } else if (cate_id && state) {
    return request.get('/my/article/list', {
      params: {
        pagenum, pagesize, cate_id, state
      }
    })
  } else if (!cate_id && !state) {
    return request.get('/my/article/list', {
      params: {
        pagenum, pagesize
      }
    })
  }
}
// 发布文章
export const publishArticle = (formData) => {
  return request({
    url: '/my/article/add',
    method: 'POST',
    data: formData
  })
}
// 获取文章详情(修改用)
export const getArticle = (id) => {
  return request.get('/my/article/info', {
    params: {
      id
    }
  })
}
// 修改文章
export const changeArticle = (formData) => {
  return request({
    url: '/my/article/info',
    method: 'PUT',
    data: formData
  })
}
// 删除文章
export const delArticle = (id) => {
  return request.delete('/my/article/info', {
    params: {
      id
    }
  })
}

// 侧边栏 相关 api
// 获取侧边栏数据
export const getMenus = (id) => {
  return request.get('/my/menus', {})
}
